home *** CD-ROM | disk | FTP | other *** search
- /* NewFindTool.c
- *
- * MPW tool to provide an enhanced front end to the standard MPW shell find command
- */
-
- #include <Strings.h>
- #include <Signal.h>
- #include <StdLib.h>
- #include <Scrap.h>
- #include <ToolUtils.h>
- #include <Lists.h>
- #include <Types.h>
- #include <Dialogs.h>
- #include <TextEdit.h>
- #include <Events.h>
- #include <OSEvents.h>
- #include <Fonts.h>
- #include <Quickdraw.h>
- #include <StdIo.h>
- #include <String.h>
-
- pascal char InputFilter(DialogPtr pdlogFind,EventRecord *pevntFind,short *psHit);
- void RefreshDialog(DialogPtr pdlogFind);
- void QuoteString(char *pszOutString,char *pszInString);
- void FindDialog(void);
- void main(void);
-
- #define FIND_BUTTON 1
- #define CANCEL_BUTTON 2
- #define CASE_SENSITIVE_CHECK 3
- #define SEARCH_BACKWARD_CHECK 4
- #define LITERAL_RADIO 5
- #define ENTIRE_WORD_RADIO 6
- #define SELECTION_EXPRESSION_RADIO 7
- #define FIND_TEXT_EDIT 8
-
- char chDialogExit; /* flag used to exit the dialog */
- char chDoubleClick; /* flag to say that a double click on a list happened */
- Point ptAction; /* current list selection point */
- ListHandle hlistFind; /* handle for a list in the dialog */
- Rect rectFindList; /* rectangle for my list */
- short sFontNum;
-
- pascal char InputFilter(DialogPtr pglogFind,EventRecord *pevntFind,short *psHit)
- /* dialog input filter */
-
- {
- Rect rectTemp;
- char chRetVal,chTest;
- short sDialogType,sLen;
- Handle hdlogItem;
- int iKeyCode,iCharCode;
- Boolean fcmdDown;
- Cell cellTemp;
- Str255 strTemp;
-
- chRetVal = false; /* initialize */
- if (pevntFind->what == mouseDown)
- {
- /* there was a mouse down event */
- ptAction = pevntFind->where; /* get click position */
- GlobalToLocal(&ptAction); /* convert to local coordinates */
- if (PtInRect(ptAction,&rectFindList) == true)
- {
- /* an event occured in the find text list */
- chDoubleClick = LClick(ptAction,pevntFind->modifiers,hlistFind);
- if (chDoubleClick == true)
- {
- cellTemp = LLastClick(hlistFind); /* find where the click occured */
- sLen = 255; /* maximum data length */
- LGetCell((strTemp + 1),&sLen,cellTemp,hlistFind); /* get a copy of the clicked on text */
- strTemp[0] = (unsigned char) sLen; /* set the length byte */
- GetDItem(pglogFind,FIND_TEXT_EDIT,&sDialogType,&hdlogItem,&rectTemp); /* get the item handle */
- SetIText(hdlogItem,strTemp); /* set the new text string */
- SelIText(pglogFind,FIND_TEXT_EDIT,sLen,sLen); /* set the new insertion point */
- *psHit = FIND_TEXT_EDIT; /* signal item affected */
- chRetVal = true; /* signal processing complete */
- } /* if chDoubleClick */
- } /* if PtInRect() */
- } /* if pevntFind */
- else
- {
- if (pevntFind->what == keyDown)
- {
- /* there was a keypress event */
- iKeyCode = pevntFind->message & keyCodeMask; /* get the key code */
- iKeyCode = iKeyCode >> 8; /* shift to low order byte */
- if ((iKeyCode == 0x24) || (iKeyCode == 0x4c))
- {
- /* Return or Enter were pressed - treat as exit request */
- chRetVal = true; /* signal processing complete */
- *psHit = ok; /* signal item affected */
- } /* if iKeyCode */
- else
- {
- fcmdDown = ((pevntFind->modifiers & cmdKey) != 0); /* is the Command key down? */
- if (fcmdDown)
- {
- *psHit = ((DialogPeek) pglogFind)->editField + 1; /* signal item effected (current TE field) */
- iCharCode = pevntFind->message & charCodeMask; /* get the character code */
- chTest = (char) iCharCode; /* convert it to a character */
- switch (chTest)
- {
- case 'x' :
- {
- DlgCut(pglogFind); /* perform cut to scrap */
- chRetVal = true; /* signal processing complete */
- break;
- } /* case 'x' */
- case 'c' :
- {
- DlgCopy(pglogFind); /* perform copy to scrap */
- chRetVal = true; /* signal processing complete */
- break;
- } /* case 'c' */
- case 'v' :
- {
- DlgPaste(pglogFind); /* perform paste from scrap */
- chRetVal = true; /* signal processing complete */
- break;
- } /* case 'v' */
- case '.' :
- {
- chRetVal = true; /* signal processing complete */
- *psHit = cancel; /* signal item affected */
- break;
- } /* case '.' */
- } /* switch chTest */
- } /* if fcmdDown */
- } /* else if iKeyCode */
- } /* if pevntFind */
- else
- {
- if (pevntFind->what == updateEvt)
- {
- if (IsDialogEvent(pevntFind))
- {
- RefreshDialog(pglogFind); /* update the non-controls */
- } /* if IsDialogEvent() */
- } /* if pevntFind */
- } /* else if pevntFind */
- } /* else if pevntFind */
- return chRetVal; /* signal if processing is complete */
- } /* InputFilter() */
-
- void RefreshDialog(DialogPtr pdlogFind)
- /* update non-controls in the dialog */
-
- {
- Rect rectTemp;
- short sDialogType,sTemp;
- Handle hdlogItem;
- ControlHandle hctrlItem;
-
- GetDItem(pdlogFind,FIND_BUTTON,&sDialogType,&hdlogItem,&rectTemp); /* get the item handle */
- PenSize(3,3); /* change pen to draw thick default outline */
- InsetRect(&rectTemp,-4,-4); /* draw outside the button by 1 pixel */
- FrameRoundRect(&rectTemp,16,16); /* draw the outline */
- PenSize(1,1); /* restore the pen size to the default value */
-
- /* Draw the upper divide line */
- PenPat(qd.gray); /* set this to a gray line */
- MoveTo(15,204); /* move to starting position */
- LineTo(350,204); /* draw to ending position */
-
- /* Draw the lower divide line */
- MoveTo(15,280); /* move to starting position */
- LineTo(350,280); /* draw to ending position */
- PenPat(qd.black); /* revert to default pen pattern */
-
- /* Draw the find prompt text */
- TextFont(systemFont);
- TextSize(12);
- GetDItem(pdlogFind,SELECTION_EXPRESSION_RADIO,&sDialogType,&hdlogItem,&rectTemp); /* get the item handle */
- hctrlItem = (ControlHandle) hdlogItem; /* change dialog handle to control handle */
- sTemp = GetCtlValue(hctrlItem); /* get the current Checkbox value */
- SetRect(&rectTemp,47,153,317,169);
- EraseRect(&rectTemp);
- MoveTo(47,166);
- if (sTemp)
- {
- DrawString("\pFind what selection expression?");
- } /* if sTemp */
- else
- {
- DrawString("\pFind what string?");
- } /* else if sTemp */
- TextFont(sFontNum);
- TextSize(9);
-
- LUpdate(pdlogFind->visRgn,hlistFind); /* update this list */
- rectTemp = rectFindList; /* start with full size */
- InsetRect(&rectTemp,-1,-1); /* set for framing */
- FrameRect(&rectTemp); /* frame it */
- } /* RefreshDialog() */
-
- void AddListString(Str255 *strAdd,ListHandle hlstString)
- /* add strings to an existing list */
-
- {
- short sRow;
- Point ptSize;
-
- if (hlstString != nil)
- {
- ptSize.h = 0; /* point to the correct column */
- sRow = LAddRow(1,32000,hlstString); /* add another row at the end of the list */
- ptSize.v = sRow; /* point to the row just added */
- LSetCell((*strAdd + 1),*strAdd[0],ptSize,hlstString); /* place string in row just created */
- LDraw(ptSize,hlstString); /* draw the new string */
- } /* if hlstString */
- } /* AddListString() */
-
- void QuoteString(char *pszOutString,char *pszInString)
- /* quote ' characters in the input string */
-
- {
- char *pchEnd,*pchLast,*pchStart;
-
- *pszOutString = '\0'; /* initialize to empty */
- pchStart = pszInString; /* initialize */
- pchEnd = pszInString; /* initialize */
- pchLast = pchStart + strlen(pszInString);
- while (pchEnd != NULL)
- {
- pchEnd = strchr(pchStart,(int) '\''); /* find the next occurance of the character ', if any */
- if ((pchEnd != NULL) && (pchStart <= pchLast))
- {
- /* a ' character was found */
- (void) strncat(pszOutString,pchStart,(size_t) (pchEnd - pchStart)); /* concatenate the input string up to but not including the ' character */
- (void) strcat(pszOutString,"'∂''"); /* quote the ' character as ∂' */
- pchStart = pchEnd + 1; /* update the string start position */
- } /* if pchEnd */
- else
- {
- /* no more ' characters to be found */
- (void) strcat(pszOutString,pchStart); /* concatenate the remaining input string */
- } /* else if pchEnd */
- } /* while pchEnd */
- } /* QuoteString() */
-
- void FindDialog(void)
- /* Find dialog box routine */
-
- {
- DialogPtr pdlogFind;
- Rect rectData,rectTemp;
- short sDialogType,sIndex,sHit,sTemp,sSearchType;
- Boolean fBeep,fGoOn,fMatch,fReverse,fSearchBackward;
- Handle hdlogItem;
- ControlHandle hctrlItem,hctrlTemp;
- Str255 strTemp;
- Point ptCSize;
- TEHandle hteString;
- DialogPeek pkdlogFind;
- char *pszEnv;
- char achTemp[256],achQuote[256];
- size_t usLen;
- FILE *pfilSetup,*pfilFindCommand;
- FontInfo fntiPrompt;
- KeyMap kmapExit;
-
- pdlogFind = GetNewDialog(2,nil,(WindowPtr) -1); /* bring in the dialog resource */
- pszEnv = getenv("font");
- (void) strcpy(achTemp,pszEnv);
- c2pstr(achTemp);
- GetFNum(achTemp,&sFontNum);
-
- rectTemp.top = pdlogFind->portRect.top; /* get window size, we will now center it */
- rectTemp.left = pdlogFind->portRect.left; /* ditto */
- rectTemp.bottom = pdlogFind->portRect.bottom; /* ditto */
- rectTemp.right = pdlogFind->portRect.right; /* ditto */
- rectTemp.top = -pdlogFind->portBits.bounds.top; /* fixed vertical position */
- rectTemp.left = ((qd.screenBits.bounds.right - qd.screenBits.bounds.left) - (rectTemp.right - rectTemp.left)) / 2; /* center horizontally */
- MoveWindow(pdlogFind,rectTemp.left,rectTemp.top,true); /* move the window to the proper position */
- SetPort(pdlogFind); /* prepare to add conditional text */
-
- TextFont(sFontNum);
- TextSize(9);
- GetFontInfo(&fntiPrompt);
- pkdlogFind = (DialogPeek) pdlogFind; /* get to the inner record */
- hteString = pkdlogFind->textH; /* get to the TE record */
- HLock((Handle) hteString); /* lock it for safety */
- (*hteString)->txFont = sFontNum;
- (*hteString)->txSize = 9;
- (*hteString)->fontAscent = fntiPrompt.ascent;
- (*hteString)->lineHeight = fntiPrompt.ascent + fntiPrompt.descent + fntiPrompt.leading;
- HUnlock((Handle) hteString); /* unLock the handle when done */
-
- SetRect(&rectFindList,47,15,317,147);
- rectTemp = rectFindList; /* start with full size */
- rectTemp.right = rectTemp.right - 15; /* make room for the scroll bar on the right */
- if (rectTemp.right <= (rectTemp.left + 15))
- {
- /* Safety check */
- rectTemp.right = rectTemp.left + 15;
- } /* if rectTemp */
- InsetRect(&rectTemp,-1,-1); /* set for framing */
- FrameRect(&rectTemp); /* frame it */
- InsetRect(&rectTemp,1,1); /* restore */
- SetRect(&rectData,0,0,1,0); /* set up list */
- ptCSize.h = rectTemp.right - rectTemp.left; /* width of the list */
- ptCSize.v = 0; /* let List Manager determine the height */
- hlistFind = LNew(&rectTemp,&rectData,ptCSize,0,pdlogFind,true,false,false,true); /* make the list */
- HLock((Handle) hlistFind);
- (*hlistFind)->selFlags = lOnlyOne + lNoNilHilite; /* set the attributes */
- HUnlock((Handle) hlistFind);
- LDoDraw(true,hlistFind); /* draw the list */
-
- pszEnv = getenv("findstrings"); /* get a pointer to the FindStrings environment variable */
- if (pszEnv != NULL)
- {
- pfilSetup = fopen(pszEnv,"r"); /* try to open the file for reading */
- if (pfilSetup != NULL)
- {
- sIndex = 0;
- while (!feof(pfilSetup))
- {
- if (fgets(achTemp,256,pfilSetup) != NULL)
- {
- usLen = strlen(achTemp);
- if (usLen > 0)
- {
- if (*(achTemp + usLen - 1) == (char) '\n')
- {
- usLen--;
- *(achTemp + usLen) = '\0'; /* remove the line feed character */
- } /* if *achTemp */
- c2pstr(achTemp);
- AddListString((Str255 *)achTemp,hlistFind);
- sIndex++;
- } /* if usLen */
- } /* if fgets() */
- } /* while !feof() */
- (void) fclose(pfilSetup);
- if (sIndex > 0)
- {
- ptCSize.v = sIndex - 1; /* cell row of last item */
- ptCSize.h = 0; /* set cell column */
- LSetSelect(true,ptCSize,hlistFind); /* select the cell */
- LAutoScroll(hlistFind); /* scroll as necessary to display the selected item */
- } /* if sIndex */
- } /* if pfilSetup */
- } /* if pszEnv */
-
- /* set up check boxes according to the enviroment variables */
- GetDItem(pdlogFind,CASE_SENSITIVE_CHECK,&sDialogType,&hdlogItem,&rectTemp); /* get the item handle */
- hctrlTemp = (ControlHandle) hdlogItem; /* change dialog handle to control handle */
- pszEnv = getenv("casesensitive"); /* get a pointer to the CaseSensitive environment variable */
- if (atoi(pszEnv) == 0)
- {
- SetCtlValue(hctrlTemp,0); /* turn the check box off */
- } /* if atoi() */
- else
- {
- SetCtlValue(hctrlTemp,1); /* turn the check box on */
- } /* else if atoi() */
- GetDItem(pdlogFind,SEARCH_BACKWARD_CHECK,&sDialogType,&hdlogItem,&rectTemp); /* get the item handle */
- hctrlTemp = (ControlHandle) hdlogItem; /* change dialog handle to control handle */
- pszEnv = getenv("searchbackward"); /* get a pointer to the SearchBackward environment variable */
- if (atoi(pszEnv) == 0)
- {
- SetCtlValue(hctrlTemp,0); /* turn the check box off */
- } /* if atoi() */
- else
- {
- SetCtlValue(hctrlTemp,1); /* turn the check box on */
- } /* else if atoi() */
-
- /* set up radio buttons according to the enviroment variable */
- for (sIndex = LITERAL_RADIO; sIndex <= SELECTION_EXPRESSION_RADIO; sIndex++)
- {
- /* clear all radios */
- GetDItem(pdlogFind,sIndex,&sDialogType,&hdlogItem,&rectTemp); /* get the Radio handle */
- hctrlTemp = (ControlHandle) hdlogItem; /* get the control handle */
- SetCtlValue(hctrlTemp,0); /* turn the radio selection off */
- } /* for sIndex */
- pszEnv = getenv("searchtype"); /* get a pointer to the SearchType environment variable */
- sIndex = LITERAL_RADIO + atoi(pszEnv); /* get the default radio sIndex */
- GetDItem(pdlogFind,sIndex,&sDialogType,&hdlogItem,&rectTemp); /* get the item handle */
- hctrlItem = (ControlHandle) hdlogItem; /* change dialog handle to control handle */
- SetCtlValue(hctrlItem,1); /* select the radio */
-
- /* set up initial highlighting */
- if (sIndex == SELECTION_EXPRESSION_RADIO)
- {
- GetDItem(pdlogFind,SEARCH_BACKWARD_CHECK,&sDialogType,&hdlogItem,&rectTemp); /* get the item handle */
- hctrlTemp = (ControlHandle) hdlogItem; /* change dialog handle to control handle */
- HiliteControl(hctrlTemp,255); /* set to disabled */
- } /* if sIndex */
-
- /* set up the default find string/selection expression according to the enviroment variables */
- GetDItem(pdlogFind,FIND_TEXT_EDIT,&sDialogType,&hdlogItem,&rectTemp); /* get the item handle */
- pszEnv = getenv("lastfindstring"); /* get a pointer to the LastFindString environment variable */
- if (pszEnv != NULL)
- {
- pfilSetup = fopen(pszEnv,"r"); /* try to open the file for reading */
- if (pfilSetup != NULL)
- {
- if (fgets(achTemp,256,pfilSetup) != NULL)
- {
- usLen = strlen(achTemp);
- if (usLen > 0)
- {
- if (*(achTemp + usLen - 1) == (char) '\n')
- {
- usLen--;
- *(achTemp + usLen) = '\0'; /* remove the line feed character */
- } /* if *achTemp */
- } /* if usLen */
- } /* if fgets() */
- (void) fclose(pfilSetup);
- } /* if pfilSetup */
- c2pstr(achTemp);
- SetIText(hdlogItem,achTemp);
- SelIText(pdlogFind,FIND_TEXT_EDIT,0,(short) strlen(pszEnv)); /* set the new insertion point */
- } /* if pszEnv */
- else
- {
- SetIText(hdlogItem,"\p");
- SelIText(pdlogFind,FIND_TEXT_EDIT,0,0); /* set the new insertion point */
- } /* else if pszEnv */
-
- RefreshDialog(pdlogFind); /* draw the non-controls */
- ShowWindow(pdlogFind); /* open a dialog box */
- SelectWindow(pdlogFind); /* make it visible */
-
- chDialogExit = false; /* do not exit dialog handle loop yet */
- do
- {
- ModalDialog((ModalFilterProcPtr) InputFilter,&sHit); /* wait until an item is hit */
- GetDItem(pdlogFind,sHit,&sDialogType,&hdlogItem,&rectTemp); /* get item information */
- hctrlItem = (ControlHandle) hdlogItem; /* get the control handle */
-
- if (sHit == FIND_BUTTON)
- {
- chDialogExit = true; /* exit the dialog when this selection is made */
- } /* if sHit */
-
- if (sHit == CANCEL_BUTTON)
- {
- chDialogExit = true; /* exit the dialog when this selection is made */
- } /* if sHit */
-
- if (sHit == CASE_SENSITIVE_CHECK)
- {
- sTemp = GetCtlValue(hctrlItem); /* get the current Checkbox value */
- SetCtlValue(hctrlItem,((sTemp + 1) & 1)); /* toggle the value */
- } /* if sHit */
-
- if (sHit == SEARCH_BACKWARD_CHECK)
- {
- sTemp = GetCtlValue(hctrlItem); /* get the current Checkbox value */
- SetCtlValue(hctrlItem,((sTemp + 1) & 1)); /* toggle the value */
- } /* if sHit */
-
- if ((sHit >= LITERAL_RADIO) && (sHit <= SELECTION_EXPRESSION_RADIO))
- {
- if (sHit == SELECTION_EXPRESSION_RADIO)
- {
- sTemp = GetCtlValue(hctrlItem); /* get the current Checkbox value */
- if (!(sTemp & 1))
- {
- /* disable SEARCH_BACKWARD_CHECK */
- GetDItem(pdlogFind,SEARCH_BACKWARD_CHECK,&sDialogType,&hdlogItem,&rectTemp); /* get the item handle */
- hctrlTemp = (ControlHandle) hdlogItem; /* change dialog handle to control handle */
- HiliteControl(hctrlTemp,255); /* set to disabled */
-
- /* update the find prompt text */
- SetRect(&rectTemp,44,153,314,169);
- EraseRect(&rectTemp);
- TextFont(systemFont);
- TextSize(12);
- MoveTo(47,166);
- DrawString("\pFind what selection expression?");
- TextFont(sFontNum);
- TextSize(9);
- } /* else if !sTemp */
- } /* if sHit */
- else
- {
- GetDItem(pdlogFind,SELECTION_EXPRESSION_RADIO,&sDialogType,&hdlogItem,&rectTemp); /* get the item handle */
- hctrlTemp = (ControlHandle) hdlogItem; /* change dialog handle to control handle */
- sTemp = GetCtlValue(hctrlTemp); /* get the current Checkbox value */
- if (sTemp & 1)
- {
- /* enable SEARCH_BACKWARD_CHECK */
- GetDItem(pdlogFind,SEARCH_BACKWARD_CHECK,&sDialogType,&hdlogItem,&rectTemp); /* get the item handle */
- hctrlTemp = (ControlHandle) hdlogItem; /* change dialog handle to control handle */
- HiliteControl(hctrlTemp,0); /* set to no highlighting */
-
- /* update the find prompt text */
- SetRect(&rectTemp,44,153,314,169);
- EraseRect(&rectTemp);
- TextFont(systemFont);
- TextSize(12);
- MoveTo(47,166);
- DrawString("\pFind what string?");
- TextFont(sFontNum);
- TextSize(9);
- } /* if sTemp */
- } /* else if sHit */
- for (sIndex = LITERAL_RADIO; sIndex <= SELECTION_EXPRESSION_RADIO; sIndex++)
- {
- /* clear all radios */
- GetDItem(pdlogFind,sIndex,&sDialogType,&hdlogItem,&rectTemp); /* get the Radio handle */
- hctrlTemp = (ControlHandle) hdlogItem; /* get the control handle */
- SetCtlValue(hctrlTemp,0); /* turn the radio selection off */
- } /* for sIndex */
- SetCtlValue(hctrlItem,1); /* turn the one radio selection on */
- } /* if sHit */
- } /* do */
- while (chDialogExit == false);
-
- /* Get results after dialog */
- fGoOn = true; /* initialize */
- GetKeys(kmapExit);
- if ((kmapExit[1] & 1) > 0)
- {
- /* a shift key was held down when exiting the dialog - temporarily reverse the search direction */
- fReverse = true;
- } /* if kmapExit[] */
- else
- {
- fReverse = false;
- } /* else if kmapExit[] */
- switch (sHit)
- {
- case FIND_BUTTON :
- {
- /* do nothing */
- break;
- } /* case REPLACE_BUTTON */
- case CANCEL_BUTTON :
- {
- fGoOn = false;
- break;
- } /* case CANCEL_BUTTON */
- } /* switch sHit */
-
- if (fGoOn)
- {
- fBeep = true; /* initialize */
- GetDItem(pdlogFind,FIND_TEXT_EDIT,&sDialogType,&hdlogItem,&rectTemp); /* get the item handle */
- GetIText(hdlogItem,&strTemp); /* get the text entered */
- if ((int) strTemp[0] > 0)
- {
- pfilFindCommand = fopen(getenv("findagainscript"),"w");
- if (pfilFindCommand != NULL)
- {
- /* the command output files were successfully opened */
- fBeep = false; /* disable error beep */
- GetDItem(pdlogFind,CASE_SENSITIVE_CHECK,&sDialogType,&hdlogItem,&rectTemp); /* get the Checkbox handle */
- hctrlItem = (ControlHandle) hdlogItem; /* get the Checkbox handle */
- (void) fprintf(pfilFindCommand,"Set CaseSensitive %d\n",GetCtlValue(hctrlItem));
-
- GetDItem(pdlogFind,SEARCH_BACKWARD_CHECK,&sDialogType,&hdlogItem,&rectTemp); /* get the Checkbox handle */
- hctrlItem = (ControlHandle) hdlogItem; /* get the Checkbox handle */
- fSearchBackward = (Boolean) GetCtlValue(hctrlItem);
- (void) fprintf(pfilFindCommand,"Set SearchBackward %u\n",fSearchBackward);
-
- sIndex = LITERAL_RADIO; /* start at the first radio in this group */
- do
- {
- GetDItem(pdlogFind,sIndex,&sDialogType,&hdlogItem,&rectTemp); /* get the radio handle */
- hctrlItem = (ControlHandle) hdlogItem; /* get the radio handle */
- sTemp = GetCtlValue(hctrlItem); /* get the radio value */
- sIndex++;
- } /* do */
- while ((sTemp != 1) && (sIndex <= SELECTION_EXPRESSION_RADIO));
- sSearchType = sIndex - LITERAL_RADIO - 1;
- (void) fprintf(pfilFindCommand,"Set SearchType %d\n",sSearchType);
-
- p2cstr(strTemp);
- pszEnv = getenv("lastfindstring"); /* get a pointer to the LastFindString environment variable */
- if (pszEnv != NULL)
- {
- pfilSetup = fopen(pszEnv,"w"); /* try to open the file for writing */
- if (pfilSetup != NULL)
- {
- (void) fprintf(pfilSetup,"%s\n",strTemp);
- (void) fclose(pfilSetup);
- } /* if pfilSetup */
- } /* if pszEnv */
-
- if (fReverse)
- {
- fSearchBackward = !fSearchBackward;
- } /* if fReverse */
-
- switch (sSearchType)
- {
- case 0 : /* literal */
- {
- QuoteString(achQuote,strTemp); /* quote ' characters as necessary */
- if (fSearchBackward)
- {
- (void) fprintf(pfilFindCommand,"Find \\'%s'\\ \"{Active}\"\n",achQuote);
- } /* if fSearchBackward */
- else
- {
- (void) fprintf(pfilFindCommand,"Find /'%s'/ \"{Active}\"\n",achQuote);
- } /* else if fSearchBackward */
- (void) fprintf(pfilFindCommand,"If {Status} != 0\nBeep\nEnd\n");
- break;
- } /* case 0 */
- case 1 : /* entire word */
- {
- QuoteString(achQuote,strTemp); /* quote ' characters as necessary */
- if (fSearchBackward)
- {
- (void) fprintf(pfilFindCommand,"Mark -y § '_New_Find_' \"{Active}\"\n");
- (void) fprintf(pfilFindCommand,"Find §¡1 \"{Active}\"\nFind Δ\\[¬{WordSet}]'%s'[¬{WordSet}]\\!1:/'%s'/Δ \"{Active}\"\nIf ({Status} != 0)\nFind '_New_Find_' \"{Active}\"\nBeep\nEnd\n",achQuote,achQuote);
- (void) fprintf(pfilFindCommand,"Unmark '_New_Find_' \"{Active}\"\n");
- } /* if fSearchBackward */
- else
- {
- (void) fprintf(pfilFindCommand,"Find Δ/[¬{WordSet}]'%s'[¬{WordSet}]/ \"{Active}\"\n",achQuote);
- (void) fprintf(pfilFindCommand,"If {Status} != 0\nBeep\nElse\nFind /'%s'/ \"{Active}\"\nEnd\n",achQuote);
- } /* else if fSearchBackward */
- break;
- } /* case 1 */
- case 2 : /* selection expression */
- {
- (void) fprintf(pfilFindCommand,"Find %s \"{Active}\"\n",strTemp);
- (void) fprintf(pfilFindCommand,"If {Status} != 0\nBeep\nEnd\n");
- break;
- } /* case 2 */
- } /* switch sSearchType */
-
- /* add the new find string to the saved find string file, but only if it is unique */
- pszEnv = getenv("findstrings"); /* get a pointer to the FindStrings environment variable */
- if (pszEnv != NULL)
- {
- pfilSetup = fopen(pszEnv,"r+"); /* try to open the file for reading */
- if (pfilSetup != NULL)
- {
- fMatch = false; /* initialize */
- while (!feof(pfilSetup) && !fMatch)
- {
- if (fgets(achTemp,256,pfilSetup) != NULL)
- {
- usLen = strlen(achTemp);
- if (usLen > 0)
- {
- if (*(achTemp + usLen - 1) == (char) '\n')
- {
- usLen--;
- *(achTemp + usLen) = '\0'; /* remove the line feed character */
- } /* if *achTemp */
- fMatch = fMatch || (strcmp(achTemp,strTemp) == 0);
- } /* if usLen */
- } /* if fgets() */
- } /* while !feof() */
- if (!fMatch)
- {
- (void) fprintf(pfilSetup,"%s\n",strTemp); /* add the unique new string to the end of the file */
- } /* if !fMatch */
- (void) fclose(pfilSetup);
- } /* if pfilSetup */
- } /* if pszEnv */
- (void) fclose(pfilFindCommand);
- } /* if pfilFindCommand */
- else
- {
- SysBeep(3);
- } /* else if pfilFindCommand */
- } /* if strTemp[] */
- if (fBeep)
- {
- SysBeep(3); /* signal error */
- } /* if fBeep */
- } /* if fGoOn */
- LDispose(hlistFind);
- DisposDialog(pdlogFind); /* flush the dialog out of memory */
- } /* FindDialog() */
-
- void main(void)
- {
- (void) signal(SIGINT,SIG_IGN); /* disable command-. because aborting with the dialog up is a BAD THING */
- InitGraf(&qd.thePort); /* initialize QuickDraw */
- SetFScaleDisable(true);
- FlushEvents(everyEvent,0); /* start with no pending events to handle */
- InitCursor(); /* start with a visible arrow cursor */
- (void) TEFromScrap(); /* Get any MPW text scrap */
- FindDialog(); /* open the modal dialog */
- FlushEvents(everyEvent,0); /* exit with no pending events to handle */
- exit(0);
- } /* main() */
-
- /* end of NewFindTool.c */